var express = require('express')
var path = require('path')
var cookieParser = require('cookie-parser')
var logger = require('morgan')
const cors = require('cors')
const { expressjwt } = require('express-jwt')
var userRouter = require('./routes/user')
var noticeRouter = require('./routes/notice')
var loginRouter = require('./routes/login')
var registerRouter = require('./routes/register')
var eventRouter = require('./routes/event')

var app = express()
app.use(cors())
app.use(logger('dev'))
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.use(cookieParser())
app.use(express.static(path.join(__dirname, 'public')))
app.use(
  expressjwt({
    secret: 'secret',
    algorithms: ['HS256'],
  }).unless({ path: ['/login', '/register'] })
)

app.use('/event', eventRouter)
app.use('/user', userRouter)
app.use('/notice', noticeRouter)
app.use('/login', loginRouter)
app.use('/register', registerRouter)

module.exports = app
